home *** CD-ROM | disk | FTP | other *** search
- #include <stdio.h>
- #include <stdlib.h>
-
- main()
- {
- char *script_name = getenv("SCRIPT_NAME");
- char *path_info = getenv("PATH_INFO");
- int count;
-
- printf("Content-type: text/html\n\n");
-
- printf("<HTML>\n");
- printf("<HEAD><TITLE>CGI Script How-to: Test Form</TITLE></HEAD>\n");
- printf("<BODY>\n");
-
- printf("<H1>CGI Script How-to<BR>determine the path of the script being executed</H1>\n");
-
- if (path_info == NULL || strcmp(path_info, "") == 0)
- {
- printf("<H2>This is the first time you called this script</H2><P>\n");
- count = 1;
- }
- else
- {
- /* Offset the path by one character to skip the leading slash (/) */
- count = atoi(path_info + 1);
- count++; /* increment the counter */
- printf("<H2>You have called this script %d times</H2><P>\n", count);
- }
-
- if (script_name != NULL)
- {
- printf("<A HREF=\"%s/%d\">Click here to call the script again</A>\n",
- script_name, count);
- }
- else
- {
- /* We can't link to the script so say it */
- printf("I don't know who to call\n");
- }
-
- printf("</BODY></HTML>\n");
- exit(0);
- }
-
- /*
- * end of count.c
- */
-